home *** CD-ROM | disk | FTP | other *** search
/ Gold Medal Software 1 / Gold Medal Software Volume 1 (Gold Medal) (1994).iso / graphics / pv3db1.arj / PV3DB191.EXE / LIST.ASM < prev    next >
Assembly Source File  |  1993-06-13  |  37KB  |  1,043 lines

  1.         Page    80,132
  2.         Title   LIST --- Display contents of ASCII file
  3.  
  4.         Comment |
  5.  
  6. Command LIST
  7. ----------------
  8.  
  9.  Purpose:  To display the contents of an ASCII file, line by
  10.            line, with operator positioning commands.
  11.  
  12.  Format:   LIST  [d:][path]filename[.ext]
  13.  
  14.  Remarks:  An ASCII file of any size may be listed.
  15.  
  16.         On the COMMAND line, enter a letter or control key:-
  17.  
  18.         Letter(s)       Control key     Function
  19.         -----------     ------------    ------------------------
  20.                         Enter           continue to next page
  21.         Q, X            ESCape          terminate and exit to DOS
  22.         T               HOME            restart from first block (top)
  23.         B               END             skip to end of file (bottom)
  24.         D               PgDn            scroll down one page
  25.         U               PgUp            scroll up one page
  26.         H or ?          F1              list commands (HELP)
  27.         L               left arrow      scroll left 20 columns
  28.         R               right arrow     scroll right 20 columns
  29.         P               up arrow        up one (previous) line
  30.         N               down arrow      down one (next) line
  31.  
  32.         /text                           find 'text'
  33.         A               F3              find next occurance of 'text'
  34.  
  35.                         ctl-HOME        restart from CURRENT block
  36.                         ctl-PgUp        restart from first block (TOP)
  37.                         ctl-PgDn        skip to end of file (BOTTOM)
  38.                         ctl-left-arrow  reset scroll to column 1
  39.  
  40.                         F1              Help
  41.                         F3              Find next
  42.                         F10             Exit
  43.         ALT S                           Strip/Don't strip MSBit             -DS
  44.         ALT C                           Display/Don't display chars 0-31    -DS
  45.  
  46.  Restrictions:
  47.         All positioning is relative to the current block in
  48.         storage. The size of the block depends on the amount of
  49.         memory available, up to 64K.
  50.  
  51.         The maximum record length currently allowed is 255.
  52.  
  53.         Logical records (ending in LF and/or CR) are placed
  54.         into the DOS screen buffer - mono or color display.
  55.         (patched, prior version didn't accept records ending in CR only)    -DS
  56.  
  57.         PC-DOS Version 2.0 or later is required.
  58.  
  59.         ANSI.SYS is NOT required.
  60.  
  61.  Scanning for text:
  62.         To scan for a character string, type a slash (/)
  63.         followed by one or more (up to 32) characters. The
  64.         scan text, but not the slash, is displayed on the
  65.         command line. The entire file, from the current line,
  66.         is scanned.
  67.  
  68.         If the text is found, the line containing it is displayed
  69.         as a blinking line.
  70.  
  71.         If the text is NOT found, an error message is displayed
  72.         and the display remains unchanged.
  73.  
  74.  Screen attributes:
  75.         There are three classes of attributes used. One for
  76.         normal display lines - lines 2 to 24, another for
  77.         special lines - lines 1 and 25, and a third for the
  78.         background color.
  79.  
  80.         These attributes may be changed by using DEBUG:
  81.  
  82.          at offset 11C = 09     ;special lines, hi-lighted or lt.blue
  83.          at offset 11D = 02     ;normal lines, green
  84.          at offset 11E = 00     ;background, black
  85.  
  86.         If these values don't match, you have a different version.
  87.         ----------------------------------------------------------
  88.  
  89.         Written by Vernon Buerg for the IBM PC using DOS 2.0,
  90.         and is supplied for public domain use. Not for sale or hire.
  91.  
  92.         Commands ALT S and ALT C added by David Schwartz, Jan. 1985     -DS
  93.         Force ASCII 8 BIT by Default By Lecointe Ludovic Juin 1993      -LL
  94.         Change: non-displayed control characters no longer occupy a     -DS
  95.                 screen display space.                                   -DS
  96.  
  97.         Version 6.0, Jan. 23, 1985 ( Version 1.5, June 2, 1984)         -DS
  98. |
  99.         Page
  100.  
  101. Bios    Segment At 40h                  ;DOS data area
  102.         Db      16 Dup (?)
  103. Flag    Dw      ?                       ;Hardware features
  104.         Db      56 Dup (?)
  105. Cols    Dw      ?                       ;Columns on screen
  106.         Db      23 Dup (?)
  107. A6845   Dw      ?                       ;Base addr for active card
  108. Bios    Ends
  109.  
  110.  
  111. Cseg    Segment Para Public 'CODE'
  112.         Assume  CS:Cseg,DS:Cseg,ES:Nothing
  113.         Org     100h
  114. List    Proc    Far
  115.         Mov     DX,Offset Stackx        ;Local stack
  116.         Mov     SP,DX
  117.         Push    DS                      ;Standard linkage
  118.         Xor     AX,AX                   ; for DOS return
  119.         Push    AX
  120.         Mov     AH,30h                  ;Check for
  121.         Int     21h                     ; DOS 2.0 or later
  122.         Cmp     AL,2
  123.         Jb      TooBad
  124.         Jmp     Start
  125.  
  126. TooBad: Mov     DX,Offset Sorry         ;Say Version 2 required
  127.         Mov     AH,9
  128.         Int     21h
  129.         Ret
  130.         Page
  131. ;       Constants and work areas
  132.  
  133. Special Db      09h                     ;Attribute for attention
  134. Normal  Db      02h                     ;Normal display attribute
  135. Foregrd Db      07h                     ;Fill attribute
  136. Blink   Equ     0Fh                     ;Hilite for FIND (143h blinks)
  137.  
  138. CR      Equ     0Dh
  139. LF      Equ     0Ah
  140. EOF     Equ     1Ah
  141. Eor     Equ     1                       ;End-of-record
  142. Nodata  Equ     2                       ;null record
  143.  
  144. Crt_Col Dw      0                       ;Columns for display monitor
  145. Crt_Buf Dw      0                       ;Addr of display buffer
  146. Crt_Prt Dw      0                       ;Addr of display port
  147.  
  148. Index   Dw      0                       ;Current record address
  149. Reclen  Dw      0                       ; length
  150. Row     Db      2                       ; display row
  151. Col     Db      1                       ; display column
  152. Attr    Db      02h                     ; screen attribute
  153. Blknum  Db      0                       ; block number
  154. Scroll  Dw      0                       ;Scroll left/right amount
  155. First   Dw      0                       ;Ptr to top line on screen
  156. Current Dw      0                       ;Ptr to top after UP one
  157. Last    Dw      0                       ;Ptr to last record
  158.  
  159. Recaddr Dw      0                       ;addr of i/o buffer
  160. Handle  Dw      0                       ;File handle from open
  161. Psize   Dw      16                      ;Size of a paragraph
  162. Blksize Dw      0                       ;File read size
  163.  
  164. Switch1 Db      0
  165. Switch2 Db      0
  166. Numlf   Db      1                       ;line feed count
  167. Numcr   Db      0                       ;C/R count
  168.  
  169. ;char_msk  db     07fh                  ; character mask (7Fh or FFh)        -DS
  170. char_msk  db     0ffh                  ; character mask (7Fh or FFh)        -LL
  171. min_disp  db     ' '                   ;lowest ord char to display(0 or ' ')-DS
  172.  
  173. TextMax Db      32                      ;Keyboard buffer
  174. TextLen Db      0
  175. TextBuf Db      32 Dup (0)              ;Scan text
  176.  
  177. Prompt  Db      'Command:'
  178. Spaces  Db      32 Dup (32)             ;Scan text entered
  179.         Db      'Keys: PgUp PgDn Arrows ESC=exit ?=Help '
  180. Pr_Len  Equ     This Byte - Prompt
  181.  
  182. TextMsg Db      '*** Text not found ***'
  183. EofMsg  Db      '   *** End-of-file ***'
  184. EofLen  Equ     This Byte - EofMsg
  185.  
  186. Work    Db      'LIST '                 ;current logical record             -DS
  187. Keyin   Db      64                      ;keyboard buffer size
  188. Keyout  Db      0                       ; and length read
  189. Filenm  Db      76 Dup (0)              ;d:path\filename.ext
  190.  
  191. Askfile Db      13,10,'Enter filename: $'
  192. Openmsg Db      '  Open failed, return code='
  193. Opencod Dw      '00'
  194.         Db      '$'
  195. Code2   Db      'File not found $'
  196. Code3   Db      'Path not found $'
  197. Code4   Db      'Too many files $'
  198. Code5   Db      'Access denied  $'
  199. Sorry   Db      Cr,Lf,'Sorry, DOS 2.0 or later required',Cr,Lf,'$'
  200.  
  201.         Org     offset Work+256
  202. Workx   Equ     $-Work
  203. Stack   Db      64 Dup (0)              ;may overlay above constants
  204. Stackx  Equ     $
  205.  
  206.         Page
  207. ;
  208. ;       Command letters and keys
  209.  
  210. What1   Db      13,32,27,81     ;Cr,Sp,Esc,Q
  211.         Db      68,85,63,72     ;D,U,?,H
  212.         Db      47,82,76,84     ;/,R,L,T
  213.         Db      80,65,78,88     ;P,A,N,X
  214.         Db      66              ;B
  215. Num1    Equ     $-What1                 ;How many letters
  216.  
  217. What2   Db      77,75,73,81     ;->,<-,PgUp,PgDn
  218.         Db      71,72,61,80     ;HOME,^,F3,v
  219.         Db      59,68,79,119    ;F1,F10,END,^HOME
  220.         Db      115,132,118     ;^<-,^PgUp,^PgDn
  221.           db     46,31                 ; ALT C, ALT S                       ;-DS
  222. Num2    Db      $-What2                 ;Number of control keys
  223.  
  224. Where1  Dw      Offset NxtPage,Offset NxtPage,Offset Close, Offset Close
  225.         Dw      Offset NxtPage,Offset Back,   Offset Got_H, Offset Got_H
  226.         Dw      Offset Got_S,  Offset Right,  Offset Left,  Offset Top
  227.         Dw      Offset Up1,    Offset Got_Rs, Offset Down1, Offset Close
  228.         Dw      Offset Bottom
  229.  
  230. Where2  Dw      Offset Right,  Offset Left,   Offset Back,  Offset NxtPage
  231.         Dw      Offset Top,    Offset Up1,    Offset Got_Rs,Offset Down1
  232.         Dw      Offset Got_H,  Offset Close,  Offset Bottom,Offset Home
  233.         Dw      Offset Scroll0,Offset Top,    Offset Bottom
  234.         dw      Offset ctrl, Offset strip                           ;-DS
  235.         Page
  236.                                ; HelpMsg updated                     -DS
  237. HelpMsg Db      CR,9,'LIST 1.5(6.0) by Vernon Buerg (Mod by DS and LL)'
  238.         Db      CR,LF
  239.         Db      CR,LF,9,'Commands and keys:'
  240.         Db      CR,LF
  241.         Db      CR,LF,9,'DY or Space ',9,9,'continue to next page'
  242.         Db      CR,LF,9,'ESC, Q, X or F10',9,' terminate'
  243.         Db      CR,LF,9,'HOME, T or Ctl PgUp',9,' restart from Top of file'
  244.         Db      CR,LF,9,'END, B or Ctl PgDn',9,' skip to Bottom of file'
  245.         Db      CR,LF,9,'Ctl Home     ',9,9,' restart from top of block'
  246.         Db      CR,LF,9,'PgDn or D    ',9,9,' scroll Down one page'
  247.         Db      CR,LF,9,'PgUp or U    ',9,9,' scroll Up one page'
  248.         Db      CR,LF,9,'H, ? or F1   ',9,9,' list Help for keys'
  249.         Db      CR,LF,9,'D or L      ',9,9,'scroll Left 20 columns'
  250.         Db      CR,LF,9,'D or R      ',9,9,'scroll Right 20 columns'
  251.         Db      CR,LF,9,'Ctl D       ',9,9,'reset scroll to column 1'
  252.         Db      CR,LF,9,' or P       ',9,9,'Previous, up one line'
  253.         Db      CR,LF,9,' or N       ',9,9,'Next, down one line'
  254.         Db      CR,LF,9,'/text        ',9,9,' find text'
  255.         Db      CR,LF,9,'A or F3      ',9,9,' find text Again'
  256.         db      CR,LF,9,"ALT S        ",9,9," do/don't Strip parity bit"
  257.         db         " (toggle)"
  258.         db      CR,LF,9,"ALT C        ",9,9," do/don't display Control "
  259.         db         " chars"
  260.  
  261.         db         " (toggle)"
  262.         Db      '$'
  263.  
  264.         Page
  265. ;
  266. ;       Initialization
  267.  
  268. Start:  Mov     BX,PgmSize              ;Length of Cseg and Stack
  269.         Mov     AH,4Ah                  ;Modify allocated memory
  270.         Int     21h                     ; using ES from entry
  271.  
  272.         Call    GetParm                 ;Get filename from command line
  273. Openit: Call    Open
  274.         Jz      Init
  275.         Ret
  276.  
  277. Close:  Mov     BX,Handle               ;End of job
  278.         Mov     AH,3Eh                  ;Close a file handle
  279.         Int     21h
  280.  
  281.         Mov     AX,0600h                ;Clear the screen
  282.         Sub     BL,BL
  283.         Mov     BH,Foregrd
  284.         Sub     CX,CX                   ;Screen begin
  285.         Mov     DX,184Fh                ; and end
  286.         Int     10h
  287.         Ret                             ;Return to DOS
  288.  
  289.         Page
  290. ;
  291. ; Allocate memory for file buffer
  292.  
  293. Init:   Mov     BX,1000h                ;Try for 64K more
  294. GetMem: Mov     AH,48h                  ;Allocate memory
  295.         Int     21h
  296.         Jc      GetMem                  ;Get what there is
  297.  
  298.         Mov     RecAddr,AX              ;Save segment addr
  299.         Mov     AX,BX                   ;Paragraphs available
  300.         Sub     AX,32                   ; less one sector
  301.         Mul     Psize                   ; as bytes available
  302.         Mov     Blksize,AX              ; and as file read size
  303.  
  304.         Call    InitCrt                 ;Get CRT buffer constants
  305.  
  306.         Call    Set1                    ;Display title line
  307.  
  308.         Call    Set25                   ;Display prompt line
  309.  
  310.         Page
  311. ;
  312. ; Extract next logical record for display
  313.  
  314. Read1:  Call    ReadBlk                 ;Load next block
  315.         Mov     BL,Normal
  316.         Mov     Attr,BL
  317.         Jnz     Read2
  318.         Jmp     AtEnd
  319.  
  320. Read2:  Dec     Row                     ;Spot for incomplete record
  321.         Cmp     Numlf,0                 ;record ended in LF?
  322.         Je      GetNext                 ;no, have col/row
  323.         Inc     Row                     ;yes, row stays where it is
  324.         Mov     Col,1                   ; and in column 1
  325.  
  326. GetNext:
  327.         Mov     AX,Index                ;Is record in buffer?
  328.         Cmp     AX,Last
  329.         Jb      GotNext
  330.         Jmp     AtEnd
  331. GotNext:
  332.         Call    ListOne                 ;Display next logical record
  333.         Mov     CX,Reclen
  334.         Add     Col,CL                  ;For end-of-block
  335.         Mov     DH,Row
  336.         Cmp     DH,25                   ;Exceeded screen?
  337.         Jne     TestEor                 ; no, read next record
  338.         Cmp     NumLF,0                 ;Ended in LF?
  339.         Jne     Wait
  340.  
  341. TEstEor:Jmp Read2                       ;End-of-records?
  342.  
  343. Wait:   Mov     AH,0                    ;Wait and read console
  344.         Int     16h
  345.  
  346.         Mov     SI,Offset Spaces        ;Clear prompt line
  347.         Call    Msg25
  348.         Page
  349. ;
  350. ; Process keyboard (command) input
  351.  
  352.         Cmp     AL,27                   ;ESCape to exit?
  353.         Jne     Chk00
  354.         Jmp     Close
  355.  
  356. Chk00:  Cmp     AL,0                    ;Control char?
  357.         Jne     Chk_97                  ; no, a letter
  358.         Xchg    AL,AH                   ; yes, get extended code
  359.         Mov     DI,Offset What2
  360.         Mov     BP,Offset Where2
  361.         Mov     CL,Num2
  362.         Jmp     Short Control
  363.  
  364. Chk_97: Cmp     AL,97                   ;Lower case?
  365.         Jl      Upper
  366.         Sub     AL,32                   ;Yes, make upper
  367.  
  368. Upper:  Mov     DI,Offset What1         ;Letter table
  369.         Mov     BP,Offset Where1        ;Where-to-go list
  370.         Mov     CL,Num1                 ;Number of entries
  371.  
  372. Control:Mov     SI,DI                   ;Find letter/code
  373.         Mov     CH,0                    ;Number in list
  374.         Push    DS
  375.         Pop     ES
  376.         Repnz   Scasb
  377.         Jne     Wait                    ; if not found
  378.         Dec     DI                      ;Point to letter/code
  379.         Sub     DI,SI                   ;Offset into list
  380.         Shl     DI,1                    ; times word size
  381.         Mov     BX,Word Ptr DS:[DI][BP]
  382.         Jmp     BX                      ;Go to routine
  383.  
  384. Right:  Cmp     Scroll,220              ;right arrow
  385.         Jb      Got77
  386.         Jmp     Wait
  387. Got77:  Add     Scroll,20
  388.         Jmp     BackUp
  389.  
  390. Scroll0:Mov     Scroll,0                ;ctrl-left-arrow
  391.         Jmp     BackUp
  392.  
  393. Left:   Cmp     Scroll,0                ;left arrow
  394.         Jne     Got75
  395.         Jmp     Wait
  396. Got75:  Sub     Scroll,20
  397.         Jmp     BackUp
  398.  
  399. Got_Rs: Call    ReScan                  ;F3 for re-scan
  400.         Jmp     NxtPage
  401.  
  402. Got_H:  Call    Help                    ;List key functions
  403.         Call    Back1
  404.         Jmp     Wait
  405.  
  406. strip:    xor    char_msk,080h         ; toggle stripping MSB               -DS
  407.           call   Back1                 ;                                    -DS
  408.           jmp    NxtPage               ;                                    -DS
  409.  
  410. ctrl:     xor    min_disp,020h         ; toggle display of chars 0-31       -DS
  411.           call   Back1                 ;                                    -DS
  412.           jmp    NxtPage               ;                                    -DS
  413.  
  414. Got_S:  Call    Scan                    ;Find text
  415.         Jmp     NxtPage
  416.  
  417.         Page
  418. NxtPage:                                ;Advance to next "page"
  419.         Mov     AX,Index
  420.         Cmp     AX,Last                 ;At end of file?
  421.         Jae     BWait
  422.         Mov     Current,AX
  423.         Mov     DH,2                    ;Restart at row 2
  424.         Mov     Row,DH
  425.         Call    Clear                   ;Clear screen
  426.         Jmp     TestEor
  427.         Page
  428. ; Scroll up one line
  429.  
  430. Up1:    Cmp     First,0                 ;Already at top?
  431.         Jne     Up12                    ; no, scroll up one more
  432. Bwait:  Jmp     AtEnd                   ; yes, ignore it
  433.  
  434. Up12:   Call    Scroll_Up               ;Display down one line
  435.         Mov     AX,Index                ; to empty top line
  436.         Mov     Current,AX              ;Save bottom line ptr
  437.         Mov     AX,First
  438.         Mov     Index,AX
  439.         Call    UpOne
  440.         Mov     Row,2
  441.         Mov     Col,1
  442.         Call    ListOne
  443.         Mov     AX,Current
  444.         Mov     Index,AX
  445.         Call    UpOne
  446.         Jmp     Wait
  447.  
  448. Home:   Mov     Index,0                 ;Restart from top of block
  449.         Jmp     NxtPage
  450.  
  451.  
  452. AtEnd:  Mov     SI,Offset EofMsg        ;say End-of-file
  453.         Call    Msg25
  454.         Jmp     Wait
  455.  
  456. Bottom: Mov     AX,Last                 ;Position to last record
  457.         Mov     Index,AX
  458.         Jmp     BackUp
  459.  
  460. Top:    Sub     CX,CX                   ;Restart
  461.         Mov     AL,0                    ; from beginning
  462.         Sub     DX,DX
  463.         Mov     AH,42h                  ;Reposition file
  464.         Mov     BX,Handle
  465.         Int     21h
  466.         Call    Clear
  467.         Mov     Row,2
  468.         Mov     Col,1
  469.         Mov     First,0
  470.         Mov     Blknum,0
  471.         Jmp     Read1
  472.  
  473. ; Scroll Up one page
  474.  
  475. Back:   Call    Back1                   ;Back up to top of page
  476. BackUp: Call    Back1                   ; or to previous page
  477.         Jmp     Nxtpage
  478.  
  479. ; Scroll down one line
  480.  
  481. Down1:  Mov     AX,Index                ;Current line
  482.         Cmp     AX,Last                 ;At end of file?
  483.         Jb      Down2
  484.         Jmp     AtEnd
  485.  
  486. Down2:  Mov     Current,AX
  487.         Mov     AX,First
  488.         Mov     Index,AX
  489.         Call    GetRec                  ;Set new first ptr
  490.         Mov     AX,Index
  491.  
  492. Down3:  Call    Scroll_Dn               ;Move display up one line
  493.         Mov     AX,Index
  494.         Mov     First,AX
  495.         Mov     AX,Current
  496.         Mov     Index,AX
  497.         Mov     Row,24
  498.         Mov     Col,1
  499.         Jmp     GetNext
  500.  
  501. ; Scroll Up one page
  502.  
  503. Back1   Proc    Near
  504.         Mov     CX,23                   ;Back to current page
  505. Back0:  Call    UpOne
  506.         Loop    Back0
  507.         Mov     Col,1
  508.         Ret
  509. Back1   Endp
  510.  
  511. ; Scroll up one line
  512.  
  513. UpOne   Proc    Near                    ;Position to previous line
  514.         Push    CX
  515.         Mov     CX,2
  516.         Cmp     Index,0                 ;Already at top?
  517.         Je      Up1d                    ; yes, no change
  518. Up1a:   Mov     ES,Recaddr              ;Buffer start
  519. Up1b:   Mov     DI,Index                ;Offset into buffer
  520.         Cmp     ES:Byte Ptr[DI],LF      ;A line feed?
  521.         Je      Up1c
  522.         Dec     Index
  523.         Jnz     Up1b                    ;Out of buffer?
  524. Up1e:   Mov     Index,0                 ; yes, stop at top
  525.         Jmp     Up1d
  526.  
  527. Up1c:   Dec     Index                   ;Passed CR
  528.         Jz      Up1d
  529.         Loop    Up1b
  530.         Inc     Index                   ;Skip over LF
  531. Up1d:   Pop     CX
  532.         Ret
  533. UpOne   Endp
  534.         Page
  535. ;
  536. ;       Place Records into Screen Buffer
  537.  
  538.         Assume  CS:Cseg,DS:Cseg,ES:Nothing
  539. Display Proc    Near
  540.         Push    AX
  541.         Push    BX
  542.         Push    CX                      ;Line length
  543.         Push    DX                      ;Row,col
  544.         Push    DI
  545.         Push    ES
  546.         Push    SI                      ;Addr of record
  547.  
  548.         Sub     AX,AX
  549.         Mov     AL,DH                   ;get row
  550.         Sub     DH,DH
  551.         Mov     DI,DX                   ; and column
  552.         Dec     DI                      ;adjust for zero offset
  553.         Dec     AX
  554.         Cmp     CX,0                    ;Skip null strings
  555.         Jng     Dsp9
  556.         Cmp     CX,80                   ;Can only display 80
  557.         Jbe     Dsp1                    ; cols at a time
  558.         Mov     CX,80
  559.  
  560. Dsp1:   Mul     Crt_Col                 ;AX = row * chars per line
  561.         Add     DI,AX                   ;DI = chars from start of screen
  562.         Shl     DI,1                    ;adjust for attribute bytes
  563.  
  564.         Mov     DX,Crt_Prt              ;Addr of card status port
  565.         Mov     ES,Crt_Buf              ;Addr of display buffer
  566.  
  567.         Mov     BH,Attr                 ;Display attribute
  568. Dsp2:   Lodsb                           ;Next character
  569. dsp2a:  Cmp     AL,min_disp            ;Don't bother with chars < min_disp -DS
  570.         Jae     Dsp3                   ;                                   -DS
  571.         Jmp     Dsp4                   ;                                   -DS
  572.  
  573. Dsp3:   Mov     BL,AL                   ;Char and attr
  574.         Call    Displa
  575. Dsp4:   Loop    Dsp2
  576.  
  577. Dsp9:   Pop     SI
  578.         Pop     ES
  579.         Pop     DI
  580.         Pop     DX
  581.         Pop     CX
  582.         Pop     BX
  583.         Pop     AX
  584.         Ret
  585.  
  586. ;  Wait for horzontal retrace
  587.  
  588. Displa: In      AL,DX                   ;Port status
  589.         Test    AL,1                    ;Is it low?
  590.         Jnz     Displa                  ; no, keep checking
  591.         Cli                             ; yes, turn off interrupts
  592. Disphi: In      AL,DX                   ;Get status
  593.         Test    AL,1                    ;Is it high?
  594.         Jz      Disphi                  ; no, keep checking
  595.  
  596.         Mov     AX,BX                   ;Attrib and char
  597.         Stosw                           ; to display buffer
  598.         Sti
  599.         Ret
  600.  
  601. Display Endp
  602.         Page
  603. ;
  604. ; Display next logical record
  605.  
  606. ListOne Proc    Near
  607.         Cmp     Row,2
  608.         Jne     List1
  609.         Mov     AX,Index
  610.         Mov     First,AX                ;Ptr to current top line
  611. List1:  Call    GetRec                  ;Return logical record
  612.         Mov     CX,Reclen               ;Record size
  613.         Sub     CL,Numlf                ; less LF
  614.         Sub     CL,Numcr                ; less CR
  615.         Mov     Reclen,CX
  616.         Or      CX,CX                   ;blank line?
  617.         Jz      List9                   ;yes, increment row only
  618.  
  619.         Mov     SI,Offset Work          ;Addr of record
  620.         Cmp     Row,2                   ;Is row valid?
  621.         Jae     List2
  622.         Mov     Row,2
  623. List2:  Mov     DH,Row                  ;destination row
  624.         Mov     DL,Col                  ; and column
  625.         Add     SI,Scroll
  626.         Sub     CX,Scroll
  627.         Call    Display                 ;put into screen buffer
  628.  
  629. List9:  Inc     Row                     ;Bump to next row
  630.         Mov     BL,Normal               ; restore attribute
  631.         Mov     Attr,BL
  632.         Ret
  633. ListOne Endp
  634.         Page
  635. ;
  636. ;       GetRec - Extract next logical record
  637. ;
  638. ; Scan the buffer for special characters and copy wanted
  639. ; data to field WORK. A logical record ends in an LF and/or CR.
  640. ; Tabs are expanded and x'0F' is deleted.
  641.  
  642. GetRec  Proc    Near
  643.         Push    ES
  644.         Push    CX
  645.         Push    SI
  646.         Push    DI
  647.  
  648. GetR:   Test    Switch1,Eor             ;Found end of file?
  649.         Jz      GetR0
  650.         Mov     AX,Last                 ; yes, set ptr to EOF
  651.         Mov     Index,AX
  652.         Call    ReadBlk                 ;Try for next block
  653.         Jnz     GetR0
  654.         Jmp     GetRd
  655.  
  656. GetR0:  Sub     DI,DI                   ;Record size/output offset
  657.         Mov     Word Ptr NumLF,DI       ;zero NUMLF and NUMCR
  658.         And     Switch2,0FFh-Nodata
  659.         Mov     ES,RecAddr              ;Set buffer segment addr
  660.  
  661. GetR2:  Mov     SI,Index                ;Current input offset
  662.         Mov     AL,ES:[SI]              ;Copy a char
  663.         Cmp     AL,Eof                  ;End of file?
  664.         Jne     GetR3
  665.         Mov     Reclen,DI
  666.         Or      Switch1,Eor             ;Indicate end-of-file
  667.         Jmp     GetR
  668.  
  669. GetR3:  And     AL,char_msk             ;mask character                    -DS
  670.         Cmp     AL,09h                  ;Is it TAB?
  671.         Jne     GetR4
  672.         Mov     CX,DI                   ;Current work size
  673.         Add     CX,8                    ;Round to 8-bytes
  674.         And     CX,0FFF8h
  675.         Sub     CX,DI                   ;Number of blanks
  676. GetR3b: Mov     Work[DI],' '            ; to insert
  677.         Inc     DI
  678.         Loop    GetR3b
  679.         Inc     Index                   ;Bump input offset
  680.         Jmp     GetR2                   ; and get next char
  681.  
  682. GetR4:                                  ;                                  -DS
  683.         Mov     Work[DI],AL             ;Copy character
  684.         Inc     DI                      ;Incr output offset
  685.         Inc     Index                   ; and input offset
  686.         Cmp     AL,Cr                   ;Is it a CR?
  687.         Jne     GetR5
  688.         Inc     NumCR                   ;Yes, incr count
  689.         cmp     ES:byte ptr[SI+1],LF    ;patch for records that end        -DS
  690.         je      GetR6                  ; in CR only                        -DS
  691.         mov     byte ptr work[di-1],LF ;                                   -DS
  692.         dec     NumCR                  ;                                   -DS
  693.         Inc     NumLF                  ;                                   -DS
  694.         Jmp     GetR8                  ;                                   -DS
  695.  
  696. GetR5:  Cmp     AL,' '
  697.         Je      GetR7
  698.         Cmp     AL,Lf                   ;Is it line feed?
  699.         Jne     GetR6
  700.         Inc     NumLF                   ;Yes, incr count
  701.         Jmp     GetR8
  702.  
  703. GetR6:  Or      Switch2,Nodata          ;Non-space found
  704.  
  705. GetR7:  Cmp     DI,255                  ;Record too big?
  706.         Je      GetR8                   ;Chop record at 255 bytes
  707.         Jmp     GetR2
  708.  
  709. GetR8:  Mov     Reclen,DI
  710.         Cmp     Work,0Fh                ;If record begins with "sun"
  711.         Jne     GetR9                   ; symbol, skip it
  712.         Jmp     GetR0
  713.  
  714. GetR9:  Test    Switch2,Nodata          ;If all blank
  715.         Jnz     GetRd
  716.         Jmp     GetR0                   ; read another one
  717.  
  718. GetRd:  Pop     DI
  719.         Pop     SI
  720.         Pop     CX
  721.         Pop     ES
  722.         Ret
  723. GetRec Endp
  724.  
  725.         Page
  726. ;
  727. ; Read a block
  728.  
  729. ReadBlk Proc    Near
  730.         Mov     Switch1,0               ;reset EOR flag
  731.         Mov     BX,Handle               ;get file handle from open
  732.         Mov     CX,Blksize              ;bytes to read
  733.         Push    DS
  734.         Mov     DS,RecAddr              ;addr of gotten memory
  735.         Sub     DX,DX                   ; with zero offset
  736.         Mov     AH,3Fh
  737.         Int     21H                     ;read a block
  738.         Pop     DS
  739.  
  740.         Or      AX,AX                   ;Any bytes read?
  741.         Jz      ReadB2                  ; no, return with ZF
  742.         Mov     Last,AX                 ; yes, set record pointers
  743.         Mov     Index,0
  744.         Mov     First,0
  745.         Mov     Current,0
  746.         Inc     Blknum
  747.         Mov     DI,Last                 ;Append EOF to buffer
  748.         Mov     ES,RecAddr
  749.         Mov     Byte Ptr ES:[DI],1Ah
  750. ReadB2: Ret
  751. Readblk Endp
  752.  
  753.         Page
  754. ;
  755. ; Scan for text entered after slash (/)
  756.  
  757. ReScan  Proc
  758.         Push    DI
  759.         Push    SI
  760.         Push    DS
  761.         Pop     ES
  762.         Jmp     Scan1
  763.  
  764. Scan:   Push    DI
  765.         Push    SI
  766.         Push    DS
  767.         Pop     ES
  768.         Mov     TextMax,32              ;Max string length
  769.         Mov     DX,Offset TextMax
  770.         Mov     AH,0Ah                  ;Read console
  771.         Int     21h
  772.  
  773. Scan1:  Sub     CX,CX
  774.         Or      CL,TextLen              ;Get and test length
  775.         Jz      NoMatch                 ; none, return as is
  776.         Mov     AX,First                ;Start with current screen
  777.         Mov     Index,AX
  778.         Call    GetRec                  ;Skip top line
  779.  
  780. Scan3:  Call    GetRec                  ;Read next logical record
  781.         Test    Switch1,Eor             ;End of data?
  782.         Jnz     NoMatch                 ; yes, NOT FOUND
  783.         Mov     AX,Index                ;Current record ptr
  784.         Cmp     AX,Last                 ;Beyond buffer?
  785.         Jae     NoMatch                 ; yes, NOT FOUND
  786.         Mov     CX,RecLen
  787.         Sub     CL,TextLen              ;Columns to search
  788.         Jle     Scan3
  789.  
  790.         Mov     AL,TextBuf              ;Scan for first char in record
  791.         Mov     DI,Offset Work          ;Current record data
  792.         Repnz   Scasb
  793.         Jne     Scan3                   ; not found
  794.         Cmp     TextLen,1               ;Whole thing done?
  795.         Je      Match
  796.         Sub     CH,CH
  797.         Mov     CL,TextLen              ;Search for rest of it
  798.         Dec     CL
  799.         Mov     SI,Offset TextBuf+1
  800.         Repe    Cmpsb
  801.         Jne     Scan3
  802.         Or      CX,CX                   ;Found it?
  803.         Jnz     Scan3                   ; no, try next record
  804.  
  805. Match:  Call    Set25                   ;Restore prompt line
  806.         Mov     Attr,Blink              ; and blink
  807.         Call    UpOne
  808.         Jmp     Scaned
  809.  
  810. NoMatch:Mov     AX,First                ;Not found,
  811.         Mov     Index,AX                ; restart at last page
  812.         Call    Set25                   ;Restore prompt line
  813.  
  814.         Mov     SI,Offset TextMsg       ;Say TEXT NOT FOUND
  815.         Add     Special,128             ;Make it blink
  816.         Call    Msg25
  817.         Sub     Special,128
  818.         Mov     Switch1,0
  819.         Mov     Col,1
  820.  
  821. Scaned: Pop     SI
  822.         Pop     DI
  823.         Ret
  824. ReScan  Endp
  825.         Page
  826. ;
  827. ; Clear screen or records window
  828.  
  829. Clear   Proc    Near                    ;Clear entire screen
  830.         Push    AX
  831.         Push    BX
  832.         Push    CX
  833.         Push    DX
  834.  
  835.         Mov     AX,0600h
  836.         Mov     BH,Foregrd
  837.         Jmp     Scroller
  838.  
  839. Scroll_Dn:                              ;Scroll list window down
  840.         Push    AX
  841.         Push    BX
  842.         Push    CX
  843.         Push    DX
  844.  
  845.         Mov     AX,0601h
  846.         Mov     BH,Foregrd
  847.         Jmp     Scroller
  848.  
  849. Scroll_Up:                              ;Scroll list window up
  850.         Push    AX
  851.         Push    BX
  852.         Push    CX
  853.         Push    DX
  854.  
  855.         Mov     AX,0701h
  856.         Mov     BH,Foregrd
  857. Scroller:
  858.         Mov     CX,0100h                ;Screen begin
  859.         Mov     DX,174Fh                ; and end
  860.         Int     10h
  861.  
  862.         Pop     DX
  863.         Pop     CX
  864.         Pop     BX
  865.         Pop     AX
  866.         Ret
  867. Clear   Endp
  868.         Page
  869. ;
  870. ;       Set top title line
  871.  
  872. Set1    Proc    Near
  873.         Mov     AX,0600h                ;Clear the screen
  874.         Sub     BL,BL
  875.         Mov     BH,Foregrd
  876.         Sub     CX,CX                   ;Screen begin
  877.         Mov     DX,184Fh                ; and end
  878.         Int     10h
  879.  
  880.         Mov     Word Ptr Work+5,0000h   ;Title in work area                 -DS
  881.         Mov     DH,1                    ;Row 1
  882.         Mov     DL,DH                   ;Column 1
  883.         Mov     SI,Offset Work
  884.         Mov     CX,79                   ;Length
  885.         Mov     BL,Special              ;Hi-intensity or yellow
  886.         Mov     Attr,BL
  887.         Call    Display
  888.         Ret
  889. Set1    Endp
  890.  
  891. ;       Set prompt line
  892.  
  893. Set25   Proc    Near
  894.         Push    DI
  895.         Push    SI
  896.         Mov     DH,25                   ;set row
  897.         Mov     DL,1                    ; and column
  898.         Mov     CX,Pr_Len               ; length
  899.         Mov     BL,Special
  900.         Mov     Attr,BL
  901.         Mov     SI,Offset Prompt
  902.         Call    Display
  903.  
  904.         Mov     AH,2                    ;Set cursor position
  905.         Mov     DX,1808h                ; to row 25, col 9
  906.         Mov     BX,0                    ; page zero
  907.         Int     10H
  908.         Pop     SI
  909.         Pop     DI
  910.         Ret
  911. Set25   Endp
  912.  
  913. ;       Display message on prompt line
  914.  
  915. Msg25   Proc    Near                    ;SI - Ptr to msg text
  916.         Mov     DH,25                   ;Clear message area
  917.         Mov     DL,10                   ; its column
  918.         Mov     CX,EofLen               ; length
  919.         Mov     BL,Special              ;Hi-intensity or yellow
  920.         Mov     Attr,BL
  921.         Call    Display
  922.         Mov     BL,Normal
  923.         Mov     Attr,BL
  924.         Ret
  925. Msg25   Endp
  926.  
  927. ;
  928. ; Initialize display constants
  929.  
  930. InitCrt Proc    Near
  931.         Push    ES
  932.         Mov     AX,Bios                 ;Point to BIOS data
  933.         Mov     ES,AX
  934.         Mov     CX,ES:Cols              ;Save display columns
  935.         Mov     Crt_Col,CX
  936.         Mov     DX,ES:A6845             ;Save card base addr
  937.         Add     DX,6                    ; point to status port
  938.         Mov     Crt_Prt,DX
  939.         Mov     Crt_Buf,0B800h          ;Default to color card
  940.         Mov     BX,ES:Flag
  941.         And     BX,30h
  942.         Cmp     BX,30h                  ;Is it mono card?
  943.         Jne     CrtSet                  ; no, set for color
  944.         Mov     Crt_Buf,0B000h          ; yes, point to mono buffer
  945. CrtSet: Pop     ES
  946.         Ret
  947. InitCrt Endp
  948.         Page
  949. ;
  950. ; HELP - Display command key usage
  951.  
  952. Help    Proc    Near                    ;Describe the commands
  953.         Call    Clear
  954.         Mov     DX,0200h                ;Position cursor
  955.         Mov     AH,2
  956.         Sub     BH,BH
  957.         Mov     BL,Foregrd
  958.         Int     10h
  959.         Mov     DX,Offset HelpMsg       ;List the text lines
  960.         Mov     AH,9
  961.         Int     21h
  962.         Mov     AH,2                    ;restore position
  963.         Mov     DX,1808h                ; to row 25, col 9
  964.         Sub     BX,BX
  965.         Int     10H
  966.         Ret
  967. Help    Endp
  968.         Page
  969. ;
  970. ; Get file name from command line
  971.  
  972. GetParm Proc    Near
  973.         Xor     AX,AX                   ;For COM, CS=DS=ES
  974.         Xor     CX,CX
  975.         Mov     AL,Byte Ptr DS:[80h]    ;Gather file name from command line
  976.         Or      CX,AX                   ;Any supplied?
  977.         Jz      GetFile                 ; no, ask for it
  978.         Mov     DI,Offset Filenm        ; yes, point to target
  979.         Mov     SI,81h                  ;Offset to parm in PSP
  980. Blanks: Lodsb
  981.         Cmp     AL,' '                  ;Skip any blanks
  982.         Je      Skipit
  983.         Stosb                           ;Copy parm to FileNm
  984. Skipit: Loop    Blanks
  985.         Ret
  986.  
  987. GetFile:
  988.         Mov     DX,Offset AskFile       ;Prompt for file name
  989.         Mov     AH,9
  990.         Int     21H
  991.         Mov     AH,0AH                  ;Buffered kybd input DOS req
  992.         Mov     DX,Offset Keyin
  993.         Int     21h
  994.  
  995.         Sub     BL,BL
  996.         Or      BL,Keyout               ;Number of chars read
  997.         Jz      GetFile                 ; none, ask for name
  998.         Mov     Filenm[BX],0            ;Overlay CR to make ASCIIZ name
  999.         Ret
  1000. GetParm Endp
  1001.  
  1002. ;  Open the file to list
  1003.  
  1004. Open    Proc    Near
  1005.         Mov     OpenCod,0               ;Reset open return code
  1006.         Mov     DX,Offset Filenm        ;OPEN file
  1007.         Mov     AL,0                    ; for read only
  1008.         Mov     AH,3DH
  1009.         Int     21H
  1010.         Mov     Handle,AX               ;save file handle
  1011.         Jnc     Opened                  ;if OPEN okay
  1012.  
  1013.         Mov     OpenCod,AX
  1014.         Cmp     AL,2                    ;Check code to be
  1015.         Jl      Error                   ; within our messages
  1016.         Cmp     AL,5
  1017.         Ja      Error
  1018.         Sub     BX,BX                   ;For message index
  1019.         Mov     BL,AL
  1020.         Mov     CL,4
  1021.         Shl     BX,CL
  1022.         Lea     DX,Code2-32[BX]         ;Point to msg text
  1023.         Jmp     Error2
  1024.  
  1025. Error:  Aam                             ;Other return codes
  1026.         Xchg    AL,AH
  1027.         Or      OpenCod,AX
  1028.         Mov     DX,Offset OpenMsg
  1029.  
  1030. Error2: Mov     AH,9
  1031.         Int     21H                     ;say OPEN FAILED
  1032. Opened: Cmp     OpenCod,0
  1033.         Ret
  1034. Open    Endp
  1035.  
  1036. List    Endp
  1037.  
  1038. PgmSize Equ     ($-Cseg+16)/16          ;Program size in paragraphs
  1039.  
  1040. cseg    ends
  1041.         end     List
  1042.  
  1043.